package com.example.course.converter;

import com.example.course.bean.Activity;
import com.example.course.dto.ActivityDTO;
import com.example.course.vo.ActivityVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 活动转换器
 *
 * @author Jasmine-drs
 * @date 2025-04-22
 */
@Component
public class ActivityConverter {

	/**
	 * DTO转实体
	 *
	 * @param dto 活动DTO
	 * @return 活动实体
	 */
	public Activity toEntity(ActivityDTO dto) {
		if (dto == null) {
			return null;
		}
		Activity entity = new Activity();
		BeanUtils.copyProperties(dto, entity);
		entity.setCreateTime(LocalDateTime.now());
		entity.setUpdateTime(LocalDateTime.now());
		return entity;
	}

	/**
	 * 实体转VO
	 *
	 * @param entity 活动实体
	 * @return 活动VO
	 */
	public ActivityVO toVO(Activity entity) {
		if (entity == null) {
			return null;
		}
		ActivityVO vo = new ActivityVO();
		BeanUtils.copyProperties(entity, vo);
		return vo;
	}

	/**
	 * 批量转换为VO列表
	 *
	 * @param entityList 活动实体列表
	 * @return 活动VO列表
	 */
	public List<ActivityVO> toVOList(List<Activity> entityList) {
		if (entityList == null) {
			return null;
		}
		List<ActivityVO> voList = new ArrayList<>(entityList.size());
		for (Activity entity : entityList) {
			voList.add(toVO(entity));
		}
		return voList;
	}
} 